package com.example.controller.tribune;

import com.example.common.Result;

import com.example.common.enums.RoleEnum;
import com.example.model.entity.other.Account;
import com.example.model.entity.tribune.Post;
import com.example.model.entity.tribune.PostSuccess;
import com.example.model.vo.DoctorVo;
import com.example.service.tribune.PostService;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 论坛帖子信息表前端操作接口
 **/
@RestController
@RequestMapping("/post")
@Api(tags = "论坛帖子信息接口")
public class PostController {

    @Resource
    private PostService postService;



    /**
     * 新增
     */
    @ApiOperation(value = "新增论坛帖子信息")
    @PostMapping("/add")
    public Result add(@RequestBody Post post) throws ParseException {
        postService.add(post);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除论坛帖子信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        postService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除论坛帖子信息")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        postService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改论坛帖子信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody Post post) {
        postService.updateById(post);
        return Result.success();
    }
    @PutMapping("/updateCount/{id}")
    public Result updateCount(@PathVariable Integer id) {
        postService.updateCount(id);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询论坛帖子信息")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Post postVO = postService.selectById(id);
        return Result.success(postVO);
    }
    /**
     * 根据ID查询点赞收藏文字数量
     */
    @ApiOperation(value = "根据ID查询点赞收藏文字数量")
    @GetMapping("/selectSuccessById/{roleId}")
    public Result selectSuccessById(@PathVariable Integer roleId) {
        PostSuccess postSuccess = postService.selectSuccessById(roleId);
        return Result.success(postSuccess);
    }


    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有论坛帖子信息")
    @GetMapping("/selectAll")
    public Result selectAll(Post post) {
        List<Post> list = postService.selectAll(post);
        return Result.success(list);
    }


    @GetMapping("/selectRandomPost")
    public Result selectRandomPost(Post post) {
        List<Post> list = postService.selectRandomPost(post);
        return Result.success(list);
    }
    @GetMapping("/selectTopPost")
    public Result selectTopPost(Post post) {
        List<Post> list = postService.selectTopPost(post);
        return Result.success(list);
    }
    @ApiOperation(value = "查询所有论坛帖子信息")
    @GetMapping("/selectFrontPost/{typeId}")
    public Result selectFrontPost(@PathVariable Integer typeId) {
        List<Post> list = postService.selectFrontPost(typeId);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询论坛帖子信息")
    @GetMapping("/selectPage")
    public Result selectPage(Post post,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Post> page = postService.selectPage(post, pageNum, pageSize);
        return Result.success(page);
    }

}
